package com.app.controller;

import com.app.pojo.User;
import com.app.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Resource
    public UserService userService;


    //查询所有
    @RequestMapping(value = "/app16/user/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> list(){
        Map<String,Object> map = new HashMap<>();
        List<User> users = userService.find();
        if(users != null){
            map.put("success",true);
            map.put("msg","成功");
            map.put("list",users);
        }else {
            map.put("success",false);
            map.put("msg","失败");

        }
        return map;
    }


    //注册用户信息
    @RequestMapping(value = "/app16/user/regist",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> regiter(User user){
        Map<String,Object> map = new HashMap<>();
       int  users = userService.regiter(user);
        if(users != 0){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");

        }
        return map;
    }

    //登录
    @RequestMapping(value = "/app16/user/login",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> login(@RequestParam String name,@RequestParam String password){
        Map<String,Object> map = new HashMap<>();
        User users = userService.login(name,password);
        if(users != null){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");

        }
        return map;
    }
    //查询
    @RequestMapping(value = "/app16/user/findone",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findone(@RequestParam String name){
        Map<String,Object> map = new HashMap<>();
        User users = userService.findon(name);
        if(users != null){
            map.put("success",true);
            map.put("msg","成功");
        }else {
            map.put("success",false);
            map.put("msg","失败");

        }
        return map;
    }



}
